package com.nf.health.app.intervention_details.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.adapter.ViewHolder;
import com.nf.health.app.intervention_details.bean.DetectionBean;
import com.nf.health.app.models.Data;
import com.nf.health.app.utils.DateUtil;

import org.jsoup.helper.DataUtil;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2016/11/24.
 */
public class DetectionAdapter extends BaseAdapter{
    List<DetectionBean> list;
    Activity activity;
    LayoutInflater inflater = null;
    public DetectionAdapter(Activity activity, List<DetectionBean> newsList) {
        this.activity = activity;
        this.list = newsList;
        inflater = LayoutInflater.from(activity);
    }
    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        if (list != null && list.size() != 0) {
            return list.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        DetectionBean item = list.get(position);
        ViewHolder holder;
        if(position%2==0){
            holder = ViewHolder.get(parent, convertView, R.layout.item_layout_detection, position);
        }else{
            holder = ViewHolder.get(parent, convertView, R.layout.item_layout_detection_bg, position);
        }
        TextView xingqi = holder.getView(R.id.xingqi);
        CheckBox checkbox1 = holder.getView(R.id.checkbox1);
        CheckBox checkbox2 = holder.getView(R.id.checkbox2);
        CheckBox checkbox3 = holder.getView(R.id.checkbox3);
        CheckBox checkbox4 = holder.getView(R.id.checkbox4);
        CheckBox checkbox5 = holder.getView(R.id.checkbox5);
        CheckBox checkbox6 = holder.getView(R.id.checkbox6);
        CheckBox checkbox7 = holder.getView(R.id.checkbox7);
        LinearLayout lin1 = holder.getView(R.id.lin1);
        LinearLayout lin2 = holder.getView(R.id.lin2);
        LinearLayout lin3 = holder.getView(R.id.lin3);
        LinearLayout lin4 = holder.getView(R.id.lin4);
        LinearLayout lin5 = holder.getView(R.id.lin5);
        LinearLayout lin6 = holder.getView(R.id.lin6);
        LinearLayout lin7 = holder.getView(R.id.lin7);

        String zhou = DateUtil.date2yyyyMMddWeek2(DateUtil.dateToString(new Date(Long.parseLong(item.getMonitortime())), "yyyy-MM-dd HH:mm:ss"));

        xingqi.setText(zhou);

        if(item.getTime0630() != null){
            if(item.getTime0630().equals("1")){
                checkbox1.setChecked(true);
            }else{
                checkbox1.setChecked(false);
            }
        }else{
            lin1.setVisibility(View.GONE);
        }
        if(item.getTime0930() != null){
            if(item.getTime0930().equals("1")){
                checkbox2.setChecked(true);
            }else{
                checkbox2.setChecked(false);
            }
        }else{
            lin2.setVisibility(View.GONE);
        }
        if(item.getTime1000() != null){
            if(item.getTime1000().equals("1")){
                checkbox3.setChecked(true);
            }else{
                checkbox3.setChecked(false);
            }
        }else{
            lin3.setVisibility(View.GONE);
        }
        if(item.getTime1330() != null){
            if(item.getTime1330().equals("1")){
                checkbox4.setChecked(true);
            }else{
                checkbox4.setChecked(false);
            }
        }else{
            lin4.setVisibility(View.GONE);
        }
        if(item.getTime1430() != null){
            if(item.getTime1430().equals("1")){
                checkbox5.setChecked(true);
            }else{
                checkbox5.setChecked(false);
            }
        }else{
            lin5.setVisibility(View.GONE);
        }
        if(item.getTime2000() != null){
            if(item.getTime2000().equals("1")){
                checkbox6.setChecked(true);
            }else{
                checkbox6.setChecked(false);
            }
        }else{
            lin6.setVisibility(View.GONE);
        }
        if(item.getTime2200() != null){
            if(item.getTime2200().equals("1")){
                checkbox7.setChecked(true);
            }else{
                checkbox7.setChecked(false);
            }
        }else{
            lin7.setVisibility(View.GONE);
        }
        return holder.getConvertView();
    }
}
